package com.wondertek.poms.dao.repo;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.wondertek.poms.dao.po.SysDictData;

/**
 * <p><b>ISysDictDataDao Description:</b> 字典数据表Dao 执行字典数据表的查询、修改、新增、删除操作</p>
 * <p>@author wzq</p>
 * <p><b>DATE</b> 2019-08-13 11:02:01</p>
 */
public interface ISysDictDataDao extends JpaRepository<SysDictData, Long>, JpaSpecificationExecutor<SysDictData> {

    @Query(value = "select * from pc_sys_dict_data where type=?1 and deleted=0 order by sort ", nativeQuery = true)
    List<SysDictData> findAllByType(String type);

    /***
     * @Author wzq
     * @Description //查询去除id对象之外有没有parentId为parId的数据，如果没有则为子节点
     * @Date 21:03 2019/8/14
     * @Param [parentId, id]
     * @return java.util.List<com.wondertek.oes.charge.common.po.SysDictData>
     **/
    @Query(value = "select * from pc_sys_dict_data where parent_id = ?1 and id <> ?2 and deleted=0", nativeQuery = true)
    List<SysDictData> findAllByParentId(Long parId, Long id);

    @Query(value = "select * from pc_sys_dict_data where parent_ids like %?1% and deleted =0", nativeQuery = true)
    List<SysDictData> findByParentIdsLike(Long id);

    @Query(value = "select * from pc_sys_dict_data where parent_id = ?1 and (deleted=0 or deleted=2)", nativeQuery = true)
    List<SysDictData> findByParentIdAndDeleted(Long parId);
}
